import 'package:shared_preferences/shared_preferences.dart';

class PreferencesManager {
  PreferencesManager._();

  static PreferencesManager? _instance;

  static PreferencesManager getInstance() {
    if (_instance == null) {
      _instance = PreferencesManager._();
    }
    return _instance!;
  }

  SharedPreferences? _preferences;

  init() async {
    if (_preferences == null) {
      _preferences = await SharedPreferences.getInstance();
    }
  }

  Future<void> putString(String key,String value){
    return _preferences!.setString(key, value);
  }

  String getString(String key) {
    return _preferences!.getString(key) ?? "";
  }

  Future<void> putBoolean(String key,bool value){
    return _preferences!.setBool(key, value);
  }

  bool getBoolean(String key) {
    return _preferences!.getBool(key) ?? false;
  }

  // Future<void> setToken(String token) {
  //   return _preferences!.setString("userinfo_token", token);
  // }
  //
  // String getToken() {
  //   return _preferences!.getString('userinfo_token') ?? "";
  // }
  //
  // Future<void> logout() async {
  //   await _preferences!.remove('userinfo_token');
  // }
  //
  // bool checkIsLogin() {
  //   return getToken().length > 0;
  // }
}
